//每次提交触发formid收集，最后再触发实际的提交
const format = require("../../utils/format.js")
let formIdArr = []
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    name: {
      type: String,
      value: '发布',
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    formIdArr :[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getFormId: function (e) {
      console.log(e)
      let formId = e.detail.formId
      let time = new Date().getTime() + 7 * 24 * 60 * 60 * 1000
      if (formId != 'the formId is a mock one') {
        formIdArr.push({
          formId: formId,
          expiresTime: format.dateformat.format(new Date(time), "yyyy-MM-dd hh:mm:ss")
        })
      }
      
      if (formIdArr.length >= 10) {
        console.log('formIdArr lenght ' + formIdArr.length)
        let temp = formIdArr
        formIdArr = []
        console.log('clear formIdArr')
        app.getFormId(temp)
      }
    },
    realSubmit() {
      console.log('trigger real submit')
      this.triggerEvent("realSubmit", {})
    }
  }
})
